//
//  QZFindsChildCell.m
//  daojiVideo
//
//  Created by adam on 2024/5/16.
//

#import "QZFindsChildCell.h"
@interface QZFindsChildCell ()
@property (strong, nonatomic) UIImageView *videoImage;
@property (strong, nonatomic) UIImageView *userImage;
@property (strong, nonatomic) UIView *footView;
@property (strong, nonatomic) UILabel *videoContent;
@property (strong, nonatomic) UILabel *userName;
@property (strong, nonatomic) UIImageView *likeImage;
@property (strong, nonatomic) UILabel *likeNumber;
@property (assign, nonatomic) CGFloat itemWidth;
@property (strong, nonatomic) UIView *adView;
@end
@implementation QZFindsChildCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.layer.cornerRadius = 10;
        self.clipsToBounds = YES;
        
        _itemWidth = (KScreen_W-3)/2;
        _videoImage = [[UIImageView alloc]init];
        _videoImage.contentMode = UIViewContentModeScaleAspectFill;
        _videoImage.layer.cornerRadius = 10;
        _videoImage.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
        _videoImage.clipsToBounds = YES;
        [self addSubview:_videoImage];
        
        _footView = [[UIView alloc]init];
        _footView.layer.cornerRadius = 10;
        _footView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
        _footView.clipsToBounds = YES;
        _footView.backgroundColor = subviewback_black;
        [self addSubview:_footView];
        
        _adView = [[UIView alloc]init];
        _adView.backgroundColor = subviewback_black;
        [self addSubview:_adView];
        
        _videoContent = [[UILabel alloc]init];
        _videoContent.textColor = [UIColor whiteColor];
        _videoContent.font = Font(14);
        _videoContent.numberOfLines = 4;
        [_footView addSubview:_videoContent];
        
        _userImage = [[UIImageView alloc]init];
        _userImage.contentMode = UIViewContentModeScaleAspectFill;
        _userImage.layer.cornerRadius = 11;
        _userImage.clipsToBounds = YES;
        [_footView addSubview:_userImage];
        
        _userName = [[UILabel alloc]init];
        _userName.textColor = [UIColor whiteColor];
        _userName.font = Font(13);
        [_footView addSubview:_userName];
        
        _likeImage = [[UIImageView alloc]init];
        _likeImage.contentMode = UIViewContentModeScaleAspectFill;
        [_footView addSubview:_likeImage];
        
        _likeNumber = [[UILabel alloc]init];
        _likeNumber.textColor = [UIColor whiteColor];
        _likeNumber.font = Font(13);
        [_footView addSubview:_likeNumber];
        
        KWeakSelf
        [_videoImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.mas_offset(0);
            make.height.mas_offset(50);
        }];
        
        [_footView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.videoImage.mas_bottom).mas_offset(0);
            make.left.bottom.right.mas_offset(0);
        }];
        [_adView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(0);
        }];
        [_videoContent mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_offset(10);
            make.right.mas_offset(-10);
        }];
        
        [_userImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.videoContent.mas_bottom).mas_offset(8);
            make.left.mas_offset(10);
            make.bottom.mas_offset(-12);
            make.height.width.mas_offset(22);
        }];
        
        [_userName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.videoContent.mas_bottom).mas_offset(8);
            make.left.equalTo(weakSelf.userImage.mas_right).mas_offset(5);
            make.width.mas_greaterThanOrEqualTo(1);
            make.height.mas_offset(22);
        }];
        
        [_likeNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.videoContent.mas_bottom).mas_offset(8);
            make.right.mas_offset(-10);
            make.height.mas_offset(22);
            make.width.mas_greaterThanOrEqualTo(1);
        }];
        _likeImage.image = KImageNamed(@"favbefore");
        [_likeImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.videoContent.mas_bottom).mas_offset(10);
            make.right.equalTo(weakSelf.likeNumber.mas_left).mas_offset(-3);
            make.height.width.mas_offset(18);
            make.left.equalTo(weakSelf.userName.mas_right).mas_offset(10);
        }];
        
    UIButton * textShowButtonTo1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        NSString * textShowButtonTitleTo1 = @"测试功能";
        [textShowButtonTo1 setTitle:textShowButtonTitleTo1 forState:UIControlStateNormal];
        NSInteger textShowArcTo1 = arc4random_uniform(22);
        NSLog(@"随机数：%ld", (long)textShowArcTo1);
    }
    return self;
    
}
- (void)findsShoeCell:(QZVideoModel *)model{
    if(model.is_ADView){
        _adView.hidden = NO;
        self.backgroundColor = UIColor.whiteColor;
        UIView *subView = (UIView *)[_adView viewWithTag:1000];
        if ([subView superview]) {
            [subView removeFromSuperview];
        }
        if(model.expressView2 != nil){
            BUNativeExpressAdView *view = model.expressView2;
            view.tag = 1000;
            [_adView addSubview:view];
        }
        
    }else{
        self.backgroundColor = viewback_black;
        _adView.hidden = YES;
        [self.videoImage sd_setImageWithURL:KUrlString(model.image)];
        CGFloat h;
        if([model.height floatValue] > [model.width floatValue]){
            h = self.itemWidth/3*4;
        }else{
            h = self.itemWidth/4*3;
        }
        [self.videoImage mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_offset(h);
        }];
    //    [_videoContent mas_updateConstraints:^(MASConstraintMaker *make) {
    //        make.height.mas_offset(model.introHeight);
    //    }];
        self.videoContent.text = model.introduce;
        [self.userImage sd_setImageWithURL:KUrlString(model.face) placeholderImage:KImageNamed(@"ic_head_defuls")];
        self.userName.text = model.nickname;
        self.likeNumber.text = [Tools NumberToShowString:[model.like_num intValue]];
    }
    
    
    
}
- (void)showTextViewSubViewToViewTo2:(UIView * )subView{

    UIView * showTextViewSubViewTo2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewSubViewTo2.clipsToBounds = YES;
    [subView addSubview:showTextViewSubViewTo2];
    UILabel * showTextViewSubViewLabelTo3 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    showTextViewSubViewLabelTo3.text = @"ppppp88888";
    [showTextViewSubViewTo2 addSubview:showTextViewSubViewLabelTo3];
    
    UIImageView * showTextViewSubViewTo3 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [subView addSubview:showTextViewSubViewTo3];

}
@end
